// pages/overdue/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    overdue: '',
    reason: '',
    actionTitle: '',
    actionOptions: [],
    actionKey: ''
  },
  openSelect (e) {
    let defaultOptions = [
      { name: '姓名1' },
      { name: '姓名2' },
      { name: '姓名3' },
      { name: '姓名4' }
    ];
    const { key, title } = e.currentTarget.dataset;
    const mapOptions = {
      followType: [{name: '上门拜访'},{name: '维护跟进'}],
      followContent: [{name: '项目推荐'},{name:'催要款项'},{name:'日常维护'},{name:'合同签订'}]
    };
    if (mapOptions[key]) {
      defaultOptions = mapOptions[key];
    }
    this.setData({
      actionOptions: defaultOptions,
      actionTitle: title,
      actionKey: key,
      selectShow: true
    });
  },
  changeText (e) {
    this.setData({
      reason: e.detail.value
    });
  },
  closeAction () {
    this.setData({ selectShow: false });
  },
  onSelect (e) {
    const { actionKey } = this.data;
    this.setData({
      [actionKey]: e.detail.name,
      selectShow: false
    });
  },
  validateForm (form) {
    const mapMessage = {
      overdue: '请选择延期至',
      reason: '请选择原因',
    };
    for (let key in form) {
      if (!form[key]) {
        wx.showToast({
          title: mapMessage[key],
          icon: 'none'
        });
        return false;
      }
    }
    return true;
  },
  save () {
    const {
      overdue,
      reason
    } = this.data;
    const params = {
      overdue,
      reason
    };
    if (!this.validateForm(params)) return;
    // TODO:请求保存接口
    wx.navigateBack({
      delta: 1,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})